<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
class Output Extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		// $this->page_auth->secure_page();
		
	}

	public function fetch_events($event_id = '00000')
	{
		$this->load->model('M_calendar','mcal');
		$result = $this->mcal->get_event($event_id);
		$html = '';
		if($result)
		{
			$from = new DateTime($result->event_start);
			$end = new DateTime($result->event_end);
			$end->modify('-1 Day');
			$diff = $from->diff($end);
			$html.= '<div>';
				$html.= '<label class="label">Name of Event</label>';
				$html.= '<p>'.htmlentities($result->event_name).'</p>';
			$html.= '</div>';
			$html.= '<hr>';

			$html.= '<div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Start Date</label>';
					$html.= '<p>'.$from->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">End Date</label>';
					$html.= '<p>'.$end->format('M d, Y').'</p>';
				$html.= '</div>';
				$html.= '<div style="width:33%;display:inline-block;">';
					$html.= '<label class="label">Days</label>';
					$html.= '<p>'.intval($diff->days + 1).'Days</p>';
				$html.= '</div>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<label class="label">Description</label>';
				$html.= '<p>'.htmlentities($result->event_desc).'</p>';
			$html.= '</div>';
			$html.= '<hr>';
			$html.= '<div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted By</label>';
					$html.= '<p>'.$result->event_created_by.'</p>';
				$html.= '</div>';
				$html.= '<div style="width:49%;display:inline-block;">';
					$html.= '<label class="label">Posted On</label>';
					$html.= '<p>'.$result->created.'</p>';
				$html.= '</div>';
			$html.= '</div>';
		}else{
			$html .= '<div class="alert-box">Unable to get events.</div>';
		}
		echo $html;
	}

	public function read_commendation($hash = '')
	{
		$x = $this->hs->decrypt($hash);
		if($x)
		{
			$this->load->model('M_student','ms');
			$result = $this->ms->read_commendation($x[0]);
			if($result)
			{
				$log = 'Successful';
			}else{
				$log = 'Error occured';
			}
			$res =  ['status'=>$result,'log'=>$log];
		}else{
			$res =  ['status'=>false,'log'=>'Invalid key sent.'];
		}

		header('Content-Type: application/json');
		echo json_encode($res);
		exit();
	}
}
